package com.xiaobai.demo.service.impl;

import com.xiaobai.demo.mapper.UserMapper;
import com.xiaobai.demo.pojo.User;
import com.xiaobai.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    // 注册用户
    @Override
    public boolean register(User user) {
        return userMapper.register(user) > 0;
    }

    // 登录验证
    @Override
    public User login(String userName, String password) {
        return userMapper.login(userName, password);
    }

    // 查询所有用户
    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    // 根据 id 查询用户
    @Override
    public User findById(Integer id) {
        return userMapper.findById(id);
    }

    // 根据用户名模糊查询用户
    @Override
    public List<User> findByUserNameLike(String userName) {
        return userMapper.findByUserNameLike(userName);
    }

    // 更新用户信息
    @Override
    public boolean update(User user) {
        return userMapper.update(user) > 0;
    }

    // 删除用户
    @Override
    public boolean delete(Integer id) {
        return userMapper.delete(id) > 0;
    }
}